﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataModel;
using DataModel.Models;
using DataModel.Mongo;
using DataModel.Test;

namespace UniversityPortal.Controllers
{
    public class TestController : Controller
    {
        public int[] RowCount = {10, 100, 1000, 10000};

        public ActionResult Insert()
        {
            var entities = new UniversityPortalEntities();
            var mongoTest = new MongoTest();
            var sqlTest = new SqlTest(entities);
            var results = new List<TestResult>();
            var lessonGenerator = new LessonGenerator();

            for (var i = 0; i < RowCount.Count(); i++)
            {
                var mongoLessons = lessonGenerator.GetMongoLessons(RowCount[i]);
                var sqlLessons = lessonGenerator.GetSqlLessons(RowCount[i], entities);
                var mongoTime = mongoTest.Insert(mongoLessons);
                var sqlTime = sqlTest.Insert(sqlLessons);
                results.Add(new TestResult(RowCount[i], sqlTime, mongoTime));
            }
            ViewBag.TestName = "Insert";
            return View(results);
        }

        public ActionResult Remove()
        {
            var entities = new UniversityPortalEntities();
            var mongoTest = new MongoTest();
            var sqlTest = new SqlTest(entities);
            var results = new List<TestResult>();

            var mongoTime = mongoTest.Remove();
            var sqlTime = sqlTest.Remove();
            results.Add(new TestResult(0, sqlTime, mongoTime));

            ViewBag.TestName = "Remove All";
            return View("Insert",results);

        }

        public ActionResult SelectAll()
        {
            var entities = new UniversityPortalEntities();
            var mongoTest = new MongoTest();
            var sqlTest = new SqlTest(entities);
            var results = new List<TestResult>();

            var mongoTime = mongoTest.SelectAll();
            var sqlTime = sqlTest.SelectAll();
            results.Add(new TestResult(0, sqlTime, mongoTime));

            ViewBag.TestName = "Select All";
            return View("Insert", results);
        }
    }
}
